dnl @synopsis AX_WITH_PROG([VARIABLE],[program],[PATH],[VALUE-IF-NOT-FOUND])
dnl
dnl @description
dnl Locates an installed program binary, placing the result in the
dnl precious variable VARIABLE. Accepts a present VARIABLE, then
dnl --with-program, and failing that searches for program in the given
dnl path (which defaults to the system path). If program is found,
dnl VARIABLE is set to the full path of the binary; if it is not found,
dnl VARIABLE is set to VALUE-IF-NOT-FOUND, which defaults to 'program'.
dnl
dnl Based on the original version by Dustin J. Mitchell <dustin@cs.uchicago.edu>
dnl and Francesco Salvestrini <salvestrini@users.sourceforge.net> from
dnl http://autoconf-archive.cryp.to/ax_with_prog.html.
dnl
dnl @author Hunter Morris  <huntermorris@gmail.com>
dnl @version 2008-03-18
AC_DEFUN([AX_WITH_PROG], [
    AC_PREREQ([2.61])

    pushdef([VARIABLE], $1)
    pushdef([EXECUTABLE], $2)
    pushdef([PATH_PROG], $3)
    pushdef([VALUE_IF_NOT_FOUND], $4)

    AC_ARG_VAR(VARIABLE, Absolute path to EXECUTABLE executable)

    AS_IF(test -z "$VARIABLE", [
    	AC_MSG_CHECKING(whether EXECUTABLE executable path has been provided)
        AC_ARG_WITH(EXECUTABLE, AS_HELP_STRING([--with-EXECUTABLE=[[[[PATH]]]]], [absolute path to EXECUTABLE executable]), [
	    AS_IF([test "$withval" != "yes"], [
	        VARIABLE="$withval"
		AC_MSG_RESULT($VARIABLE)
	    ], [
		VARIABLE=""
	        AC_MSG_RESULT([no])
	    ])
	], [
	    AC_MSG_RESULT([no])
	])

        AS_IF(test -z "$VARIABLE", [
	    AC_PATH_PROG([]VARIABLE[], []EXECUTABLE[], []VALUE_IF_NOT_FOUND[], []PATH_PROG[])
        ])
    ])

    popdef([VALUE_IF_NOT_FOUND])
    popdef([PATH_PROG])
    popdef([EXECUTABLE])
    popdef([VARIABLE])
])
